<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-model-item label="年份">
                   <year-select :show-all="true" :value.sync="queryParam.startYear" :value2.sync="queryParam.endYear" />
                </a-form-model-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table 
      :columns="columns" 
      @expandedRowRender="expandedRowRender" 
      :data-source="dataSource"
      :rowKey="item => item.id"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange"
      >
       <span slot="operation" slot-scope="text, record">
          <a @click="handleDetails(record)">查看</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="clickdelete(record.id)">删除</a>
        </span>
          <a-table
          slot="expandedRowRender"
           slot-scope="record" 
          :columns="innerColumns"
          :data-source="record.culturalTourismList"
          :pagination="false"
          >
          <span slot="ratio" slot-scope="text"> {{getNum(text)}} </span>
        </a-table>
      </a-table>
    </div>
    <cultural-modal ref="modalForm" @ok="modalFormOk" @close="close"></cultural-modal>
  </a-card>
</template>

<script>
  import { getAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import culturalModal from './modal/culturalModal.vue'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import YearSelect from '@/components/jeecg/YearDateSelect.vue'
  import NP from 'number-precision'
  import { delTqppCulturalTourism } from '@/api/dashboardPaltform'
  export default {
    name: 'culturalTourList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      YearSelect,
      JDictSelectTag,
      culturalModal,
    },
    data () {
      return {
        createTime:[],
        positionList:[],
        description: '文化服务营业额',
        innerColumns : [
            { title: '品类', dataIndex: 'category', key: 'category' },
            { title: '营业额（万元）', dataIndex: 'turnover', key: 'turnover' },
            { title: '占比（%）', dataIndex: 'ratio', key: 'ratio', scopedSlots: { customRender: 'ratio' }},
        ],
        // 表头
         columns: [
            { title: '年份', dataIndex: 'year', key: 'year' },
            { title: '游客量（万人次）', dataIndex: 'visitorsNumber', key: 'visitorsNumber' },
            { title: '总营业额（万元）', dataIndex: 'turnover', key: 'turnover' },
            { title: '操作', key: 'operation', scopedSlots: { customRender: 'operation' } },
        ],  
        dataSource:[],
        innerData:[],
        isorter:{
        },
        url: {
          list: "/loquat/tqppCulturalTourism/list",
          delete: "/loquat/tqppCulturalTourism/delete",
        },
        dictOptions:{},
      }
    },
     watch: {
      dataSource: {
        handler (val) {
          if(val){
            // val.map(item=>{
              // this.innerData.push(...item.plantNumberList)
            // })
          }
        },
        immediate: true,
        deep: true
      }
    },
    mounted() {
        this.getTxppSubjectList()
    },
    computed: {
    },
    methods: {
       close(){
          this.searchQuery()
        },
       clickdelete(id) {
          this.$confirm({
            title: '您确定要删除该条记录吗？',
            onOk: () => {
              this.delTqppCulturalTourism(id)
            },
            onCancel() {
              console.log('Cancel')
            },
            centered: true,
          })
        },
        async delTqppCulturalTourism(val) {
            let res = await delTqppCulturalTourism({id:val})
            if(res.success){
              this.$message.success(res.message)
              this.searchQuery()
            }else{
              this.$message.error(res.message)
            }
        },
        getNum(val){
          return NP.round(NP.times(val,100), 2) + '%'
        },
        getTxppSubjectList() {
            getAction('/loquat/txppSubject/allList').then((res) => {
                this.positionList = res.result
            })
        },
        initDictConfig(){
        }
    }
  }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';
.table-page-search-wrapper{
/deep/ .ant-calendar-range-picker-input{
    font-size: 12px
  }
}
</style>